<?php
	session_start();

	include("mysql_connect.php");
	
	$_SESSION['PropertyId'] = $_POST['arg'];
	//if(strlen($_POST['arg']) > 0)
	//{
		$strKeyWord = $_SESSION['PropertyId'];
	//}
	//else
	//{
	//	$strKeyWord = "O";
	//}
//*
	$strSqlCommand = "SELECT idResidentialProperty, idListing, Currency, TotalRooms, BathTotal, StreetNumber, StreetDirPrefix, StreetName, UnitNumber, City, StateOrProvince, PostalCode, PublicRemarks
						FROM ResidentialProperty tbRP
						LEFT JOIN Listing  tbLT			ON tbRP.Listing_idListing = tbLT.idListing
						LEFT JOIN StreetAddress  tbSA	ON tbLT.StreetAddress_idStreetAddress = tbSA.idStreetAddress
						LEFT JOIN ListingData  tbLD		ON tbLT.ListingData_idListingData = tbLD.idListingData
						LEFT JOIN CurrencyFormat  tbPR	ON tbLD.Price = tbPR.idCurrencyFormat
						LEFT JOIN Baths  tbBT			ON tbBt.idBaths = tbRp.Baths_idBaths
						LEFT JOIN Rooms  tbRM			ON tbRm.idRooms = tbRp.Rooms_idRooms	
						WHERE tbRP.idResidentialProperty = ". $strKeyWord;

	$result = mysql_query($strSqlCommand);
	$rowDetail = @mysql_fetch_array($result);	

	$strAddress = $rowDetail['StreetNumber']. '+'.$rowDetail['StreetName'] . '+' . $rowDetail['City'] . '+' . $rowDetail['StateOrProvince'];
	
	$_SESSION["MapAddress"] = 'https://maps.googleapis.com/maps/api/staticmap?center=' . $strAddress. 
								'&amp;zoom=14&amp;size=288x200&amp;markers='.$strAddress.'&amp;sensor=false" width="288" height="200';


	$strSqlCommand = "SELECT FirstName, LastName FROM REAgent tbAg
						LEFT JOIN SalesData tbSD			ON tbSD.AgentID = tbAg.AgentID
						LEFT JOIN Listing tbLT				ON tbLT.SalesData_idSalesData = tbSD.idSalesData
						LEFT JOIN ResidentialProperty tbRP	ON tbRP.Listing_idListing = tbLT.idListing
						WHERE tbRP.idResidentialProperty = ". $strKeyWord;
	$result = mysql_query($strSqlCommand);
	$rowBroker = @mysql_fetch_array($result);	

	echo '<div class="property-params">';
		echo "<p>".$rowDetail['StreetNumber']." ".$rowDetail['StreetName']." ".$rowDetail['UnitNumber']."</p>";
		echo "<p>".$rowDetail['City'].", ".$rowDetail['StateOrProvince'].", ".$rowDetail['PostalCode']."</p>";
		//echo '</p>';
	//echo '<p>' . $strKeyWord . '</p>';
		echo "<p>".$rowDetail['TotalRooms']." Bedrooms, ".$rowDetail['BathTotal']." Bathrooms</p>";
		echo "<p>".$rowDetail['Currency']."</p>";
	echo '</div>';

	echo '<div class="property-image">';
	
		$filename = 'images/Residential_Photo/Photo'.$rowDetail['idListing'].'-1.jpeg';
		$nImgIdx = 2;
//		if (file_exists($filename))
//		{
//			echo '<img src="http://23.21.84.9/'.$filename.'" />';
//		}
		while( file_exists($filename) )
		{
			echo '<img src="http://23.21.84.9/'.$filename.'" />';
			$filename = 'images/Residential_Photo/Photo'.$rowDetail['idListing'].'-'.$nImgIdx.'.jpeg';
			$nImgIdx++;
		}

	echo '</div>';

	echo '<div class="property-description">';
	echo '<p>';
	echo '<span style="font-family: arial,helvetica,sans-serif; font-size: small;">';
	echo $rowDetail['PublicRemarks'];
	echo '</span>';
	if( isset($rowBroker['FirstName'] ) )
		echo $rowBroker['FirstName'] . " ". $rowBroker['LastName'] ;
	echo '</p>';
	echo '</div>';
	
	//$strAddress = $rowDetail[0]. ' '.$rowDetail[1] . ' ' . $rowDetail[2] . ' ' . $rowDetail[3];
	//$strAddress = str_replace( " ","+", $strAddress);
	echo '<img src="'.$_SESSION["MapAddress"].'" />';
	$_SESSION["MapAddress"] = 'https://maps.googleapis.com/maps/api/staticmap?center=' . $strAddress. 
								'&amp;zoom=14&amp;size=288x400&amp;markers='.$strAddress.'&amp;sensor=false" width="288" height="400';
//*/
?>